import {
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  OneToMany,
  Entity,
  Unique,
} from 'typeorm';
import { Food } from '../../entities';
import { IsOptional, IsString } from 'class-validator';
import { ApiHideProperty } from '@nestjs/swagger';

@Entity('category')
@Unique(['categoryName'])
export class Category {
  @PrimaryGeneratedColumn('increment')
  categoryId: number;

  @IsString()
  @Column()
  categoryName: string;

  /** 
   * 分类标签 
   * 午餐、晚餐、加餐 
   * @example 午餐
   */
  @IsString()
  @Column()
  @IsOptional()
  tag?: string;

  @ApiHideProperty()
  @OneToMany(() => Food, (food) => food.category)
  foods?: Food[];

  @CreateDateColumn()
  createdAt?: Date;
}
